package ru.spbu.mm.diploma.client.controller;

import ru.spbu.mm.diploma.common.entity.Project;
import ru.spbu.mm.diploma.common.facade.ProjectFacadeImpl;

import javax.faces.component.UIInput;
import java.util.List;

/**
 *
 */
public class ProjectController {
    private List<Project> projects;
    private Project project;
    private boolean isDisabled = true;

    private UIInput nameInputText;
    private UIInput descriptionInputText;

    public String getInfo() {
        return "info";
    }

    public String edit() {
        isDisabled = false;
        return null;
    }

    public String save() {
        isDisabled = true;
        project.setName((String)nameInputText.getSubmittedValue());
        project.setDescription((String)descriptionInputText.getSubmittedValue());
        return null;
    }

    public String update() {
        ProjectFacadeImpl.getInstance().updateProject(project);
        //todo add popup window with information about successful saving
        return null;
    }

    public List<Project> getProjects() {
        return ProjectFacadeImpl.getInstance().getProjects();
    }

    public void setProjects(List<Project> projects) {
        this.projects = projects;
    }

    public Project getProject() {
        return project;
    }

    public void setProject(Project project) {
        this.project = project;
    }

    public boolean getIsDisabled() {
        return isDisabled;
    }

    public void setIsDisabled(boolean isDisabled) {
        isDisabled = isDisabled;
    }

    public UIInput getNameInputText() {
        return nameInputText;
    }

    public void setNameInputText(UIInput nameInputText) {
        this.nameInputText = nameInputText;
    }

    public UIInput getDescriptionInputText() {
        return descriptionInputText;
    }

    public void setDescriptionInputText(UIInput descriptionInputText) {
        this.descriptionInputText = descriptionInputText;
    }
}
